<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 200px;
        height: 200px;
        border: 1px solid red;
      }
    </style>
  </head>
  <body>
    <button id="btn">提交</button>
    <div id="box"></div>
    <button id="start">开始</button>
    <button id="stop">结束</button>
    <script>
      var btnEle = document.getElementById('btn');
      btnEle.disabled = true;

      //每隔2换色
      var startEle = document.getElementById('start');
      var boxEle = document.getElementById('box');
      var stopEle = document.getElementById('stop');
      var timer
      function color() {
        var str = '0123456789abcdef';
        var rgb = '#';
        for (var i = 0; i < 6; i++) {
          rgb += str[number(0, str.length - 1)];
        }
        return rgb;
      }
      function number(min, max) {
       var res= Math.round(Math.random() * (max - min)) + min;
        return res;
      }
      console.log(startEle);
      startEle.onclick = function () {
        startEle.disabled = true
       timer= setInterval(function(){
            boxEle.style.backgroundColor = color();
        },1000)
      };
      stopEle.onclick = function(){
        startEle.disabled = !startEle.disabled
        clearInterval(timer)
      }
    </script>
  </body>
</html>
